%MY_1DBOXFILTER preforms a 1D box filter in spatial space.
%nf the function in the 1D spatial domain
%w the radius of thebox filter (overall filter size: w+1+w) 
function [ df ] = my_1DBoxFilter( f, w )

N = size(f,2);
area = (2*w+1)^2;
mult = 1/area;

%Concatenate the vector 2*w more times
m = f;
for i = 1:2*w
   m = [m;f]; 
end

%Mean filter
for k = 1:N
    avg = 0;
    start_j = k-w;
    end_j = k+w;
    
    if start_j < 1
        start_j = 1;
    end
    if end_j > N
        end_j = N;
    end
    
   for i = 1:2*w+1
      for j = start_j:end_j
         avg = avg + mult*m(i,j);
      end
   end
   
   %Filtered value
   df(k) = avg;
   
end

end

